<?php
namespace app\common\model;
use app\common\model\CommonModel;
use think\Db;

class Rule extends CommonModel
{
	/**
	* 添加规则信息
	*/
	public function serRule($data)
	{
		return $this->insert($data);
	}
	/**
	* 修改规则信息
	*/
	public function updateRule($where,$data)
	{
		return $this->where($where)->update($data);
	}
	/**
	* 获取列表信息
	*/
	public function ruleList($where,$field)
	{
		$item = $this->where($where)->order('sort DESC')->field($field)->select();
        return empty($item) ? array():$item->toArray();
	}
	/**
	* 获取列表信息
	*/
	public function ruleNavList($field,$arid = [])
	{
		if($arid)
		{
			return $this->where($where)->field($field)->select();
		}else{
			return $this->where($where)->field($field)->select();
		}
	}
	/**
	* 获取规则信息列表
	*/
	public function getRuleList($limit = 10,$page)
	{
	   $item = $this->field("arid,name,param,title,pid,level,sort,ascription,nav")->paginate($limit,false,['page'=>$page]);
       return empty($item) ? array():$item->toArray();
	}
	/**
	* 获取某一个字段
	* $where 条件
	* $field 字段名称
	*/
	public function getRuleField($where,$field)
	{
		return $this->where($where)->value($field);
	}
	/**
	* 删除一条信息
	*/
	public function delRule($where)
	{
		return $this->where($where)->delete();
	}
	/**
	* 获取数量
	*/
	public function countNum($arid,$auth)
	{
		return $this->where('arid','in',$arid)->where('name',$auth)->count();
	} 
	/**
	* 获取数量
	*/
	public function columns($arid,$auth)
	{
		return $this->where('arid','in',$arid)->where('name',$auth)->field('arid,param')->select();
	} 
}
